package org.mch.func.ftp;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.io.SocketInputStream;
import org.mch.comm.exec.MsgException;
import org.mch.comm.ftp.DownloadStatus;
import org.mch.comm.ftp.FileDESEncrypt;
import org.mch.comm.ftp.FtpParam;
import org.mch.comm.ftp.HtFTPClient;
import org.mch.comm.ftp.UploadStatus;

/**
 * 描述：FTP服务工具类，实现上传、下载及目录下文件浏览（分：包括子目录和不包括子目录）；<BR>
 * 
 * 类名：FTPServiceTool.java<BR>
 * 
 * @author zl；DateTime：2007-6-2<BR>
 * 
 *         说明：<BR>
 * <BR>
 */
public class MCFTPClient {

	private FtpParam ftpParam;

	private HtFTPClient ftpClient = new HtFTPClient();

	public MCFTPClient() {
		// 设置将过程中使用到的命令输出到控制台
		this.ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
	}

	/**
	 * 连接到FTP服务器
	 * 
	 * @return 是否连接成功
	 * @throws IOException
	 */
	public boolean connect() throws IOException {
		ftpClient.connect(this.getFtpParam().getAddress(), this.getFtpParam().getPort());
		ftpClient.setControlEncoding("GBK");
		if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
			if (ftpClient.login(this.getFtpParam().getUsername(), this.getFtpParam().getPassword())) {
				return true;
			}
		}
		disconnect();
		return false;
	}

	public byte[] download(String remote) throws Exception {

		if (remote == null || remote.trim().equals("")) {
			throw new MsgException("下载文件异常：远程文件路径（remote）为空！");
		}

		// 设置被动模式
		ftpClient.enterLocalPassiveMode();
		// 设置以二进制方式传输
		ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
		ftpClient.setControlEncoding("GBK");

		if (remote.substring(0, 1).equals("/")) {
			remote = remote.substring(1, remote.length());
		}

		List<Byte> listbyte = new ArrayList<Byte>();

		// 根据设置的根目录重新设置远程文件；
		String remoteFileName = this.getFtpParam().getRootpath() + remote;

		// 检查远程文件是否存在
		FTPFile[] files = ftpClient.listFiles(new String(remoteFileName));

		if (files.length != 1) {
			System.out.println("远程文件不存在");
			return null;
		}

		long lRemoteSize = files[0].getSize();

		InputStream in = ftpClient.retrieveFileStream(remoteFileName);

		byte[] bytes = new byte[1];
		double step = lRemoteSize / 100D;
		double process = 0D;
		long localSize = 0L;
		int c;

		in.read(bytes);

		while ((c = in.read(bytes)) != -1) {
			listbyte.add(bytes[0]);
			localSize += c;
			double nowProcess = localSize / step;
			if (nowProcess > process) {
				process = nowProcess;
				if (process % 10 == 0)
					System.out.println("下载进度：" + process);
				// 更新文件下载进度,值存放在process变量中
			}
		}

		if (listbyte != null && listbyte.size() > 0) {
			byte[] downbytes = new byte[listbyte.size()];
			for (int i = 0; i < listbyte.size(); i++) {
				downbytes[i] = listbyte.get(i);
			}
			return downbytes;
		}
		in.close();
		boolean upNewStatus = ftpClient.completePendingCommand();

		DownloadStatus result;

		if (upNewStatus) {
			result = DownloadStatus.Download_New_Success;
		} else {
			result = DownloadStatus.Download_New_Failed;
		}

		System.out.println(result);

		return null;
	}

	public FtpParam getFtpParam() {
		return ftpParam;
	}

	/**
	 * 从FTP服务器上下载文件,支持断点续传，上传百分比汇报
	 * 
	 * @param remote
	 *            远程文件路径
	 * @param local
	 *            本地文件路径
	 * @return 上传的状态
	 * @throws IOException
	 */
	public DownloadStatus download(String remote, String local) throws Exception {
		return this.download(remote, new File(local), false);
	}

	/**
	 * 从FTP服务器上下载文件,支持断点续传，上传百分比汇报
	 * 
	 * @param remote
	 *            远程文件路径
	 * @param local
	 *            本地文件路径
	 * @return 上传的状态
	 * @throws IOException
	 */
	public DownloadStatus download(String remote, String local, boolean isDecrypt) throws Exception {
		return this.download(remote, new File(local), isDecrypt);
	}

	/**
	 * 从FTP服务器上下载文件,支持断点续传，上传百分比汇报
	 * 
	 * @param remote
	 *            远程文件路径
	 * @param local_file
	 *            本地文件
	 * @return 上传的状态
	 * @throws IOException
	 */
	public DownloadStatus download(String remote, File local_file, boolean isDecrypt) throws Exception {

		if (remote == null || remote.trim().equals("")) {
			throw new MsgException("下载文件异常：远程文件路径（remote）为空！");
		}

		if (isDecrypt) {
			// 解密下载
			this.decrpytDownload(remote, local_file);
		}

		// 设置被动模式
		ftpClient.enterLocalPassiveMode();
		// 设置以二进制方式传输
		ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
		ftpClient.setControlEncoding("GBK");
		DownloadStatus result;

		if (remote.substring(0, 1).equals("/")) {
			remote = remote.substring(1, remote.length());
		}

		// 根据设置的根目录重新设置远程文件；
		String remoteFileName = this.getFtpParam().getRootpath() + remote;

		// 检查远程文件是否存在
		FTPFile[] files = ftpClient.listFiles(remoteFileName);

		if (files.length != 1) {
			System.out.println("远程文件不存在");
			return DownloadStatus.Remote_File_Noexist;
		}

		long lRemoteSize = files[0].getSize();

		// 本地存在文件，进行断点下载
		if (local_file.exists()) {
			long localSize = local_file.length();
			// 判断本地文件大小是否大于远程文件大小
			if (localSize >= lRemoteSize) {
				System.out.println("本地文件大于远程文件，下载中止");
				return DownloadStatus.Local_Bigger_Remote;
			}

			// 进行断点续传，并记录状态
			FileOutputStream out = new FileOutputStream(local_file, true);
			ftpClient.setRestartOffset(localSize);
			InputStream in = ftpClient.retrieveFileStream(remoteFileName);
			byte[] bytes = new byte[1024];
			double step = lRemoteSize / 100D;
			double process = localSize / step;
			int c;

			while ((c = in.read(bytes)) != -1) {

				// 不解密上传文件
				out.write(bytes, 0, c);

				localSize += c;
				double nowProcess = localSize / step;
				if (nowProcess > process) {
					process = nowProcess;
					if (process % 10 == 0)
						System.out.println("下载进度：" + process);
					// 更新文件下载进度,值存放在process变量中
				}
			}
			in.close();
			out.close();
			boolean isDo = ftpClient.completePendingCommand();
			if (isDo) {
				result = DownloadStatus.Download_From_Break_Success;
			} else {
				result = DownloadStatus.Download_From_Break_Failed;
			}
		} else {
			OutputStream out = new FileOutputStream(local_file);
			InputStream in = ftpClient.retrieveFileStream(remoteFileName);

			byte[] bytes = new byte[1024];
			double step = lRemoteSize / 100D;
			double process = 0D;
			long localSize = 0L;
			int c;

			while ((c = in.read(bytes)) != -1) {
				out.write(bytes, 0, c);
				localSize += c;
				double nowProcess = localSize / step;
				if (nowProcess > process) {
					process = nowProcess;
					if (process % 10 == 0)
						System.out.println("下载进度：" + process);
					// 更新文件下载进度,值存放在process变量中
				}
			}
			in.close();
			out.close();
			boolean upNewStatus = ftpClient.completePendingCommand();
			if (upNewStatus) {
				result = DownloadStatus.Download_New_Success;
			} else {
				result = DownloadStatus.Download_New_Failed;
			}
		}
		return result;
	}

	/**
	 * 功能：解密下载；<br>
	 * 
	 * 说明：<br>
	 * 
	 * @author：zl；Date：2007-6-19<br>
	 * 
	 * @param remote
	 * @param local_file
	 * @return
	 * @throws Exception
	 */
	private DownloadStatus decrpytDownload(String remote, File local_file) throws Exception {

		if (remote == null || remote.trim().equals("")) {
			throw new MsgException("下载文件异常：远程文件路径（remote）为空！");
		}

		FileDESEncrypt fdese = new FileDESEncrypt(this.getFtpParam().getSecretkey());

		// 设置被动模式
		ftpClient.enterLocalPassiveMode();
		// 设置以二进制方式传输
		ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
		ftpClient.setControlEncoding("GBK");
		DownloadStatus result;

		if (remote.substring(0, 1).equals("/")) {
			remote = remote.substring(1, remote.length());
		}

		// 根据设置的根目录重新设置远程文件；
		String remoteFileName = this.getFtpParam().getRootpath() + remote;

		// 检查远程文件是否存在
		FTPFile[] files = ftpClient.listFiles(remoteFileName);

		if (files.length != 1) {
			System.out.println("远程文件不存在");
			return DownloadStatus.Remote_File_Noexist;
		}

		long lRemoteSize = files[0].getSize();

		// 本地存在文件，进行断点下载
		if (local_file.exists()) {
			long localSize = local_file.length();
			// 判断本地文件大小是否大于远程文件大小
			if (localSize >= lRemoteSize) {
				System.out.println("本地文件大于远程文件，下载中止");
				return DownloadStatus.Local_Bigger_Remote;
			}

			// 进行断点续传，并记录状态
			FileOutputStream out = new FileOutputStream(local_file, true);
			ftpClient.setRestartOffset(localSize);
			InputStream in = ftpClient.retrieveFileStream(remoteFileName);

			Integer c;

			List<Byte> bytelist = new ArrayList<Byte>();

			while ((c = in.read()) != -1) {

				bytelist.add(c.byteValue());
			}

			byte[] bytes = new byte[bytelist.size()];

			for (int i = 0; i < bytelist.size(); i++) {
				bytes[i] = bytelist.get(i);
			}

			// 解密当前二进制流
			byte[] decryptBytes = fdese.decryptBytes(bytes);
			out.write(decryptBytes);

			in.close();
			out.close();
			boolean isDo = ftpClient.completePendingCommand();
			if (isDo) {
				result = DownloadStatus.Download_From_Break_Success;
			} else {
				result = DownloadStatus.Download_From_Break_Failed;
			}

		} else {
			FileOutputStream out = new FileOutputStream(local_file);
			SocketInputStream in = (SocketInputStream) ftpClient.retrieveFileStream(remoteFileName);

			Integer c;

			List<Byte> bytelist = new ArrayList<Byte>();

			while ((c = in.read()) != -1) {

				bytelist.add(c.byteValue());
			}

			byte[] bytes = new byte[bytelist.size()];

			for (int i = 0; i < bytelist.size(); i++) {
				bytes[i] = bytelist.get(i);
			}

			// 解密当前二进制流
			byte[] decryptBytes = fdese.decryptBytes(bytes);
			out.write(decryptBytes);

			in.close();
			out.close();
			boolean upNewStatus = ftpClient.completePendingCommand();
			if (upNewStatus) {
				result = DownloadStatus.Download_New_Success;
			} else {
				result = DownloadStatus.Download_New_Failed;
			}
		}
		return result;
	}

	/**
	 * 上传文件到FTP服务器，支持断点续传
	 * 
	 * @param local
	 *            本地文件名称，绝对路径
	 * @param remote
	 *            远程文件路径，使用/home/directory1/subdirectory/file.ext
	 *            按照Linux上的路径指定方式，支持多级目录嵌套，支持递归创建不存在的目录结构
	 * @return 上传结果
	 * @throws IOException
	 */
	public UploadStatus upload(String local, String remote) throws Exception {

		if (local == null) {
			throw new Exception("上传的本地文件路径为空！请检查！");
		}

		if (local.indexOf(".", local.lastIndexOf("/")) == -1) {
			throw new Exception("上传的文件路径需要包含文件类型，如：test.ini、test.txt等等");
		}

		return this.upload(new File(local), remote, false);
	}

	/**
	 * 上传文件到FTP服务器，支持断点续传
	 * 
	 * @param local
	 *            本地文件名称，绝对路径
	 * @param remote
	 *            远程文件路径，使用/home/directory1/subdirectory/file.ext
	 *            按照Linux上的路径指定方式，支持多级目录嵌套，支持递归创建不存在的目录结构
	 * @return 上传结果
	 * @throws IOException
	 */
	public UploadStatus upload(String local, String remote, boolean isEncrypt) throws Exception {

		if (local == null) {
			throw new Exception("上传的本地文件路径为空！请检查！");
		}

		if (local.indexOf(".", local.lastIndexOf("/")) == -1) {
			throw new Exception("上传的文件路径需要包含文件类型，如：test.ini、test.txt等等");
		}

		return this.upload(new File(local), remote, isEncrypt);
	}

	/**
	 * 上传文件到FTP服务器，支持断点续传
	 * 
	 * @param local_file
	 *            本地文件
	 * @param remote
	 *            远程文件路径，使用/home/directory1/subdirectory/file.ext
	 *            按照Linux上的路径指定方式，支持多级目录嵌套，支持递归创建不存在的目录结构
	 * @return 上传结果
	 * @throws IOException
	 */
	public UploadStatus upload(File local_file, String remote) throws Exception {
		return this.upload(local_file, remote, false);
	}

	/**
	 * 上传文件到FTP服务器，支持断点续传
	 * 
	 * @param local_file
	 *            本地文件
	 * @param remote
	 *            远程文件路径，使用/home/directory1/subdirectory/file.ext
	 *            按照Linux上的路径指定方式，支持多级目录嵌套，支持递归创建不存在的目录结构
	 * @return 上传结果
	 * @throws IOException
	 */
	public UploadStatus upload(File local_file, String remote, boolean isEncrypt) throws Exception {

		// 设置PassiveMode传输
		ftpClient.enterLocalPassiveMode();
		// 设置以二进制流的方式传输
		ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
		ftpClient.setControlEncoding("GBK");
		UploadStatus result;

		if (remote.substring(0, 1).equals("/")) {
			remote = remote.substring(1, remote.length());
		}

		// 根据设置的根目录重新设置远程文件；
		String remoteFileName = this.getFtpParam().getRootpath() + remote;

		// 创建服务器远程目录结构，创建失败直接返回
		if (CreateDirecroty(remoteFileName, ftpClient) == UploadStatus.Create_Directory_Fail) {
			System.out.println("创建服务器远程目录结构" + UploadStatus.Create_Directory_Fail);
			return UploadStatus.Create_Directory_Fail;
		}

		// 检查远程是否存在文件
		FTPFile[] files = ftpClient.listFiles(remoteFileName);
		if (files.length == 1) {
			long remoteSize = files[0].getSize();

			long localSize = local_file.length();
			if (remoteSize == localSize) {
				return UploadStatus.File_Exits;
			} else if (remoteSize > localSize) {
				return UploadStatus.Remote_Bigger_Local;
			}

			// 尝试移动文件内读取指针,实现断点续传
			result = uploadFile(remoteFileName, local_file, ftpClient, remoteSize, isEncrypt);
			// 如果断点续传没有成功，则删除服务器上文件，重新上传
			if (result == UploadStatus.Upload_From_Break_Failed) {
				if (!ftpClient.deleteFile(remoteFileName)) {
					return UploadStatus.Delete_Remote_Faild;
				}
				result = uploadFile(remoteFileName, local_file, ftpClient, 0, isEncrypt);
			}
		} else {
			result = uploadFile(remoteFileName, local_file, ftpClient, 0, isEncrypt);
		}
		return result;
	}

	/**
	 * 功能：返回当前目录所有文件，包括子目录，使用递归；<br>
	 * 
	 * @author：zl；Date：2007-6-1<br>
	 * @param pathname
	 * @return
	 * @throws IOException
	 */
	public List<String> browseAll(String pathname) throws IOException {

		List<String> filelist = new ArrayList<String>();

		FTPFile[] ftpfiles = this.ftpClient.listFiles(pathname);

		for (int i = 0; i < ftpfiles.length; i++) {
			FTPFile temp = ftpfiles[i];
			if (temp.isFile()) {
				filelist.add(ftpfiles[i].getName());
			} else if (temp.isDirectory()) {
				filelist = this.browseChild(temp, pathname, filelist);
			}
		}

		return filelist;
	}

	private List<String> browseChild(FTPFile ftpfile, String current_pathname, List<String> filelist) throws IOException {

		if (ftpfile.isFile()) {
			return filelist;
		}

		// 当前FTPFile对象的目录名；
		String childdirectory = ftpfile == null ? "" : ftpfile.getName();

		// 当前目录的Path；
		String child_current_pathname = current_pathname + childdirectory + "/";

		FTPFile[] ftpfiles = this.ftpClient.listFiles(child_current_pathname);

		for (int i = 0; i < ftpfiles.length; i++) {
			FTPFile temp = ftpfiles[i];
			if (temp.isFile()) {
				filelist.add(ftpfiles[i].getName());
			} else if (temp.isDirectory()) {
				filelist = this.browseChild(temp, child_current_pathname, filelist);
			}
		}

		return filelist;
	}

	/**
	 * 功能：返回当前目录下的所有文件，不包括子目录；<br>
	 * 
	 * @author：zl；Date：2007-6-1<br>
	 * @param pathname
	 * @return
	 * @throws IOException
	 */
	public List<String> browse(String pathname) throws IOException {

		List<String> filelist = new ArrayList<String>();

		FTPFile[] ftpfiles = this.ftpClient.listFiles(pathname);

		for (int i = 0; i < ftpfiles.length; i++) {
			FTPFile temp = ftpfiles[i];
			if (temp.isFile()) {
				filelist.add(ftpfiles[i].getName());
			}
		}

		return filelist;
	}

	/**
	 * 断开与远程服务器的连接
	 * 
	 * @throws IOException
	 */
	public void disconnect() throws IOException {
		if (ftpClient.isConnected()) {
			ftpClient.disconnect();
		}
	}

	/**
	 * 递归创建远程服务器目录<br>
	 * 
	 * 注意：文件及路径编码问题，请在传入参数前处理；<br>
	 * 
	 * @param remote
	 *            远程服务器文件绝对路径
	 * @param ftpClient
	 *            FTPClient对象
	 * @return 目录创建是否成功
	 * @throws IOException
	 */
	public UploadStatus CreateDirecroty(String remote, FTPClient ftpClient) throws IOException {
		UploadStatus status = UploadStatus.Create_Directory_Success;
		String directory = remote.substring(0, remote.lastIndexOf("/") + 1);
		if (!directory.equalsIgnoreCase("/") && !ftpClient.changeWorkingDirectory(new String(directory))) {
			// 如果远程目录不存在，则递归创建远程服务器目录
			int start = 0;
			int end = 0;
			if (directory.startsWith("/")) {
				start = 1;
			} else {
				start = 0;
			}
			end = directory.indexOf("/", start);
			while (true) {
				String subDirectory = new String(remote.substring(start, end));
				if (!ftpClient.changeWorkingDirectory(subDirectory)) {
					if (ftpClient.makeDirectory(subDirectory)) {
						ftpClient.changeWorkingDirectory(subDirectory);
					} else {
						System.out.println("创建目录失败");
						return UploadStatus.Create_Directory_Fail;
					}
				}

				start = end + 1;
				end = directory.indexOf("/", start);

				// 检查所有目录是否创建完毕
				if (end <= start) {
					break;
				}
			}
		}
		return status;
	}

	/**
	 * 上传文件到服务器,新上传和断点续传
	 * 
	 * @param remoteFile
	 *            远程文件名，在上传之前已经将服务器工作目录做了改变
	 * @param localFile
	 *            本地文件File句柄，绝对路径
	 * @param processStep
	 *            需要显示的处理进度步进值
	 * @param ftpClient
	 *            FTPClient引用
	 * @param isEncrypt
	 * @return
	 * @throws Exception
	 */
	public UploadStatus uploadFile(String remoteFile, File localFile, FTPClient ftpClient, long remoteSize, boolean isEncrypt)
			throws Exception {

		// 设置以二进制方式传输
		ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
		ftpClient.setControlEncoding("GBK");

		// 加密上传文件；
		if (isEncrypt) {
			return this.encryptUploadFile(remoteFile, localFile, ftpClient, remoteSize);
		}

		UploadStatus status;

		// 显示进度的上传
		double step = localFile.length() / 100D;

		double process = 0;

		long localreadbytes = 0L;

		RandomAccessFile raf = new RandomAccessFile(localFile, "r");
		OutputStream out = ftpClient.appendFileStream(remoteFile);
		// 断点续传
		if (remoteSize > 0) {
			ftpClient.setRestartOffset(remoteSize);
			process = remoteSize / step;
			raf.seek(remoteSize);
			localreadbytes = remoteSize;
		}
		byte[] bytes = new byte[1024];
		int c;

		while ((c = raf.read(bytes)) != -1) {

			out.write(bytes, 0, c);

			localreadbytes += c;
			if (localreadbytes / step != process) {
				process = localreadbytes / step;
				System.out.println("上传进度:" + process);
				// 汇报上传状态
			}
		}

		out.flush();
		raf.close();
		out.close();
		boolean result = ftpClient.completePendingCommand();
		if (remoteSize > 0) {
			status = result ? UploadStatus.Upload_From_Break_Success : UploadStatus.Upload_From_Break_Failed;
		} else {
			status = result ? UploadStatus.Upload_New_File_Success : UploadStatus.Upload_New_File_Failed;
		}
		return status;
	}

	/**
	 * 功能：加密上传文件<br>
	 * 
	 * 说明：<br>
	 * 
	 * @author：zl；Date：2007-6-14<br>
	 * 
	 * @param remoteFile
	 * @param localFile
	 * @param ftpClient
	 * @param remoteSize
	 * @return
	 * @throws Exception
	 */
	private UploadStatus encryptUploadFile(String remoteFile, File localFile, FTPClient ftpClient, long remoteSize)
			throws Exception {

		FileDESEncrypt fdese = new FileDESEncrypt(this.getFtpParam().getSecretkey());

		byte[] encrypt_byte = fdese.encryptFile(localFile);

		UploadStatus status;

		RandomAccessFile raf = new RandomAccessFile(localFile, "r");
		OutputStream out = ftpClient.appendFileStream(new String(remoteFile));

		out.write(encrypt_byte);

		out.flush();
		raf.close();
		out.close();

		boolean result = ftpClient.completePendingCommand();
		if (remoteSize > 0) {
			status = result ? UploadStatus.Upload_From_Break_Success : UploadStatus.Upload_From_Break_Failed;
		} else {
			status = result ? UploadStatus.Upload_New_File_Success : UploadStatus.Upload_New_File_Failed;
		}
		return status;
	}

	/**
	 * 功能：删除指定的文件；<br>
	 * 
	 * 说明：注意pathname可能存在编码问题，请在传入前自己转换；<br>
	 * 
	 * @author：zl；Date：2007-7-9<br>
	 * 
	 * @param pathname
	 * @return
	 * @throws Exception
	 */
	public boolean deleteFile(String pathname) throws Exception {
		return ftpClient.deleteFile(pathname);
	}

	public HtFTPClient getFtpClient() {
		return ftpClient;
	}

	public void setFtpClient(HtFTPClient ftpClient) {
		this.ftpClient = ftpClient;
	}

	public static void main(String[] args) {
		MCFTPClient myFtp = new MCFTPClient();
		try {
			myFtp.getFtpParam().setAddress("172.16.5.199");
			myFtp.getFtpParam().setPort(56);
			myFtp.getFtpParam().setUsername("admin");
			myFtp.getFtpParam().setPassword("admin888");
			myFtp.getFtpParam().setRootpath("/");
			myFtp.connect();
			// List<String> list = myFtp.browseAll("/DB2/");
			//
			// for (int i = 0; i < list.size(); i++) {
			// System.out.println(list.get(i));
			// }
			myFtp.getFtpParam().setSecretkey("AD67EA2F3BE6E5ADD368DFE03120B5DF92A8FD8FEC2F0746");
			myFtp.upload("C:\\Users\\lilu20090904\\Downloads\\测试WORD文档AS.docx",
					"/xxh/htztb/supplier_info/1002AA1000000000QD2P/测试WORD文档AS.docx");
			// true);
			// myFtp.download("test/佳丽餐饮.xls", new File("d:/佳丽餐饮.xls"), true);
			// myFtp.deleteFile("/xxh/htztb/supplier_info/1002AA1000000000QD2P/华泰招投标管理_数据结构设计.pdm");
			// myFtp.download("/test/test.txt", "c:/test.ini");
			// myFtp.ftpClient.makeDirectory(new
			// String("电视剧".getBytes("GBK"),"iso-8859-1"));
			// myFtp.ftpClient.changeWorkingDirectory(new
			// String("电视剧".getBytes("GBK"),"iso-8859-1"));
			// myFtp.ftpClient.makeDirectory(new
			// String("走西口".getBytes("GBK"),"iso-8859-1"));
			// System.out.println(myFtp.upload("E:\\yw.flv", "/yw.flv",5));
			// System.out.println(myFtp.upload("E:\\走西口24.mp4","/央视走西口/新浪网/走西口24.mp4"));
			// System.out.println(myFtp.download("/央视走西口/新浪网/走西口24.mp4",
			// "E:\\走西口242.mp4"));
			myFtp.disconnect();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}